<?
    require_once("mvc/action/ActionForm.php");
    require_once("mvc/action/ActionMessage.php");
    require_once("mvc/action/ActionMessages.php");

    require_once("cms/download/om/DownloadRevision.php");


    class BaseDownloadForm extends ActionForm {

        protected $revision;
        protected $publicationDay;
        protected $publicationMonth;
        protected $publicationYear;
        protected $formFile;
        protected $formImage;
        protected $deleteImage;
        protected $roles;
        protected $overwrite;

        public function __construct() {
            $this->revision = new DownloadRevision();
            $this->publicationDay = null;
            $this->publicationMonth = null;
            $this->publicationYear = null;
            $this->formFile = null;
            $this->formImage = null;
            $this->deleteImage = false;
            $this->roles = array();
            $this->overwrite = false;
        }

        public function getRevision() {
            return $this->revision;
        }

        public function setRevision(DownloadRevision $revision) {
            $this->revision = $revision;
        }

        public function getPublicationDay() {
            return $this->publicationDay;
        }

        public function setPublicationDay($publicationDay) {
            $this->publicationDay = $publicationDay;
        }

        public function getPublicationMonth() {
            return $this->publicationMonth;
        }

        public function setPublicationMonth($publicationMonth) {
            $this->publicationMonth = $publicationMonth;
        }

        public function getPublicationYear() {
            return $this->publicationYear;
        }

        public function setPublicationYear($publicationYear) {
            $this->publicationYear = $publicationYear;
        }

        public function getFormFile() {
            return $this->formFile;
        }

        public function setFormFile($formFile) {
            $this->formFile = $formFile;
        }

        public function getFormImage() {
            return $this->formImage;
        }

        public function setFormImage($formImage) {
            $this->formImage = $formImage;
        }

        public function getDeleteImage() {
            return $this->deleteImage;
        }

        public function setDeleteImage($deleteImage) {
            $this->deleteImage = $deleteImage;
        }

        public function getRoles() {
            return $this->roles;
        }

        public function setRoles($roles) {
            $this->roles = $roles;
        }

        public function getOverwrite() {
            return $this->overwrite;
        }

        public function setOverwrite($overwrite) {
            $this->overwrite = $overwrite;
        }

        public function validate() {

            $errors = new ActionMessages();

            if(is_null($this->getRevision()->getDownload()->getDescription()) || strlen($this->getRevision()->getDownload()->getDescription()) == 0)
                $errors->add("revision->download->description",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.description", true)));


            if(!is_null($this->getRevision()->getDownload()->getDescription()) && strlen($this->getRevision()->getDownload()->getDescription()) > 0 && strlen($this->getRevision()->getDownload()->getDescription()) > 255)
                $errors->add("revision->download->description",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("prompt.description", true),
                        new ActionMessage("255", false))));


            global $ALLOWABLE_IMAGES;
            if(!is_null($this->getFormImage()) && isset($this->formImage["size"]) && $this->formImage["size"] > 0 && !array_key_exists($this->formImage["type"], $ALLOWABLE_IMAGES))
                $errors->add("formImage",
                    new ActionMessage("errors.image", true, new ActionMessage("prompt.image", true)));

            return $errors;
        }

    }
?>